//
//  SEGOpenDoorAlertView.m
//  ExcellentHome
//
//  Created by 揭婧雯 on 2018/3/29.
//  Copyright © 2018年 陈区. All rights reserved.
//

#import "SEGOpenDoorAlertView.h"

@implementation SEGOpenDoorAlertView

- (void)showWithTitle:(NSString *_Nullable)title text:(NSString *_Nullable)text
{
    self.frame = CGRectMake(0, 0, LYScreenWidth(), LYScreenHeight());
    [[[UIApplication sharedApplication] keyWindow] addSubview:self];
    
    self.backgroundColor = kColor_bg3;
    
    //白色背景视图
    UIView *contentView = [[UIView alloc] init];
    contentView.backgroundColor = kColor_W;
    contentView.layer.masksToBounds = YES;
    contentView.layer.cornerRadius = 5;
    [self addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker* make) {
        make.centerX.equalTo(self.mas_centerX);
        make.centerY.equalTo(self.mas_centerY);
        make.width.mas_equalTo(270.0);
    }];
    
    //标题
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.textColor = kColor_2;
    titleLabel.font = kFont_13;
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.numberOfLines = 0;
    titleLabel.textAlignment = NSTextAlignmentLeft;
    [contentView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker* make) {
        make.centerX.equalTo(contentView.mas_centerX);
        make.top.equalTo(contentView).offset(29);
        make.left.equalTo(contentView).offset(15);
        make.right.equalTo(contentView).offset(-15);
    }];
    titleLabel.text = title;
    
    //内容
    UILabel *contentLabel = [[UILabel alloc] init];
    contentLabel.textColor = kColor_1;
    contentLabel.font = kFont_13;
    contentLabel.backgroundColor = [UIColor clearColor];
    contentLabel.numberOfLines = 0;
    contentLabel.textAlignment = NSTextAlignmentLeft;
    [contentView addSubview:contentLabel];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker* make) {
        make.centerX.equalTo(contentView.mas_centerX);
        make.top.equalTo(titleLabel.mas_bottom);
        make.left.equalTo(contentView).offset(15);
        make.right.equalTo(contentView).offset(-15);
    }];
    contentLabel.text = text;

    //按钮
    UIButton *button = [[UIButton alloc] init];
    button.backgroundColor = [UIColor clearColor];
    [button setTitle:@"确认" forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:16];
    button.layer.borderWidth = 0.5;
    button.layer.borderColor = kColor_L2.CGColor;

    [button addTarget:self action:@selector(seg_buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker* make) {
        make.top.equalTo(contentLabel.mas_bottom).offset(29);
        make.left.equalTo(contentView.mas_left);
        make.right.mas_equalTo(contentView.mas_right);
        make.height.mas_equalTo(44);
        make.bottom.mas_equalTo(contentView);
    }];
    
    [button setTitleColor:kColor_T forState:UIControlStateNormal];

}

- (void)seg_buttonClick:(UIButton*)sender
{
    [self removeFromSuperview];
}

@end
